package cn.lijiancn01.demo.framework.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
public class R<T> {
    private int status;
    private String msg;
    private T data;

    public static <T> R<T> data(T data) {
        R<T> r = new R();
        r.data = data;
        return r;
    }

    public static <S> R<PageResult<S>> page(long total, List<S> rows) {
        return data(new PageResult((int) total, rows));
    }

    public static <T> R<T> error(String msg) {
        return error(-1, msg);
    }

    public static <T> R<T> error(int status, String msg) {
        R<T> r = new R();
        r.msg = msg;
        r.status = status;
        return r;
    }
}
